import java.util.Arrays;
import java.util.Date;
import java.net.*;
import spread.*;

public class Producer {

    public static void main(String[] args) {
        Producer tool = new Producer();
        tool.run();
    }

    public void run() {
		SpreadConnection connection = new SpreadConnection();
		try{
			InetAddress addr = InetAddress.getByName("localhost");
			
			System.out.println("Connecting to daemon :" + addr  );
			connection.connect( addr , 0, "Producer", false, false);
			
			SpreadMessage message = new SpreadMessage();
			
			message.addGroup("group");
			//message.setReliable();
			message.setUnreliable();
			long aValues[] = new long[2];
			for( long n = 0 ; n < 1000 ; n++ )
			{
				aValues[0] = n;
				aValues[1] = System.nanoTime();
				message.setObject(aValues);
				System.out.println("Sending message " + aValues[0] + " : " + aValues[1] );
				connection.multicast(message);
				Thread.sleep(100);
			}
		}
		catch( Exception e )
		{
			System.out.println("Exception : " + e );
		}
    }
}